package com.example.lottery.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Value("${swagger.enabled}")
    private  boolean swagger_is_enable;

    @Bean
    public Docket petApi() {
        //添加header参数
        return new Docket(DocumentationType.SWAGGER_2)
                .enable(swagger_is_enable)
                .apiInfo(apiInfo(" 接口数据"))
                .groupName("defaultApi")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.lottery.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    @SuppressWarnings("deprecation")
    private ApiInfo apiInfo(String title) {
        return new ApiInfoBuilder()
                .title("接口文档")
                .contact(new Contact("", "", ""))
                .version("1.0")
                .termsOfServiceUrl("")
                .description("lottery")
                .build();
    }



}
